﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.InboundServiceRef;

    public class InboundServiceClientProxy : BasePage
    {
        public string BatchExecutePalletizing(List<string> receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.BatchExecutePalletizing(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string BatchRevertPalletizing(List<string> receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.BatchRevertPalletizing(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string CancelPalletizing(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.RevertPalletizing(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string CheckExternalIDExist(string externalID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.CheckExternalIDExist(externalID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string CheckPoIsGeneratedASN(string PoID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.CheckPoIsGeneratedASN(PoID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string CheckSAPValidation(string recepitID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.CheckSAPValidation(recepitID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string CloseReceipt(List<string> receiptIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.CloseReceipt(receiptIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteReceiptInfo(List<string> receiptIDS)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.DeleteReceiptInfo(receiptIDS, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ExecutePalletizing(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.ExecutePalletizing(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ExecuteScanReceiving(List<ReceiptDetailInfo> receiptDetailList)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.ExecuteScanReceiving(receiptDetailList, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public AdjustmentInfo GetAdjustmentInfoByID(string adjustmentID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            AdjustmentInfo adjustmentInfo = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                adjustmentInfo = client.GetAdjustmentInfoByID(adjustmentID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return adjustmentInfo;
        }

        public DataSet GetAdjustmentInfoByQueryEntity(AdjustmentQueryEntity adjustmentQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                ds = client.GetAdjustmentInfoByQueryEntity(adjustmentQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetAllReceiptInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                ds = client.GetAllReceiptInfo(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public static InboundServiceClientProxy GetInstance()
        {
            return new InboundServiceClientProxy();
        }

        public DataSet GetOutReceiptByQueryList(ReceiptQueryEntity receiptQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                ds = client.GetOutReceiptByQueryList(receiptQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public ReceiptInfo GetReceiptByReceiptID(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptInfo receiptInfo = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                receiptInfo = client.GetReceiptByReceiptID(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptInfo;
        }

        public ReceiptInfo GetReceiptInfoByID(string receiptID, ReceiptDetailQueryEntity receiptDetailQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptInfo receiptInfo = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                receiptInfo = client.GetReceiptInfoByID(receiptID, receiptDetailQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptInfo;
        }

        public ReceiptInfo GetReceiptInfoByID4Exec(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptInfo receiptInfo = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                receiptInfo = client.GetReceiptInfoByID4Exec(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptInfo;
        }

        public ReceiptInfo GetReceiptInfoByID4ExecByPagerQuery(string receiptID, ReceiptDetailQueryEntity receiptDetailQueryEntity, ReceiptHistoryQueryEntity receiptHistoryQueryEntity, PutawayDetailQueryEntity putawayDetailQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptInfo receiptInfo = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                receiptInfo = client.GetReceiptInfoByID4ExecByPagerQuery(receiptID, receiptDetailQueryEntity, receiptHistoryQueryEntity, putawayDetailQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptInfo;
        }

        public DataSet GetReceiptInfoByQueryEntity(ReceiptQueryEntity receiptQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                ds = client.GetReceiptInfoByQueryEntity(receiptQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public ReceiptInfo GetReceiptScanReceivingByID(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptInfo receiptInfo = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                receiptInfo = client.GetReceiptScanReceivingByID(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptInfo;
        }

        public ReceiptInfo ImporFormSo(string soID, List<string> lineID, string receiptID, string receiptLineID, string receiptType)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptInfo receiptInfo = null;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                receiptInfo = client.ImporFormSo(soID, lineID, receiptID, receiptLineID, receiptType, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptInfo;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InportFromPO(string poID, string receiptID, string type, string createBy)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.ImportFormPo(poID, receiptID, type, createBy, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertReceiptInfo(ReceiptInfo receiptInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.InsertReceiptInfo(receiptInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ReceiptRevert(AdjustmentInfo adjustmentInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.ReceiptRevert(adjustmentInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateReceiptInfo(ReceiptInfo receiptInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.UpdateReceiptInfo(receiptInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateSkuWeight(string ownerID, List<string> skuID, List<string> weight, List<string> skuStyle)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundServiceClient client = new InboundServiceClient("WSHttpBinding_IInboundService");
            try
            {
                result = client.UpdateSkuWeight(ownerID, skuID, weight, skuStyle, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

